//
//  VisitorView.swift
//  SinaWeiBo
//
//  Created by ZKJ on 2017/8/28.
//  Copyright © 2017年 ZKJ. All rights reserved.
//

import UIKit

class VisitorView: UIView {
    // MARK:- 提供快速通过xib创建的类方法
    class func visitorView() -> VisitorView {
        return Bundle.main.loadNibNamed("VisitorView", owner: self, options: nil)?.first as! VisitorView
    }
    
    // MARK:- 控件的属性
    @IBOutlet weak var rotateView: UIImageView!
    @IBOutlet weak var logoImageView: UIImageView!
    @IBOutlet weak var logoLabel: UILabel!
    @IBOutlet weak var registerBtn: UIButton!
    @IBOutlet weak var loginBtn: UIButton!
    
    // MARK:- 自定义函数(通过自定义函数给控件的属性赋值)
    func setUpVisitorViewInfo(iconName : String, logoText : String) {
        logoImageView.image = UIImage(named: iconName)
        logoLabel.text = logoText
        rotateView.isHidden = true
    }
    
    func addRotationAnim() {
        // 添加动画
        let rotationAnim = CABasicAnimation(keyPath: "transform.rotation.z")
        
        // 设置动画的属性
        rotationAnim.fromValue = 0
        rotationAnim.toValue = Double.pi
        rotationAnim.repeatCount = MAXFLOAT
        rotationAnim.duration = 5
        
        /* When true, the animation is removed from the render tree once its
         * active duration has passed. Defaults to YES. */
        // 应用从前台切到后台，再从后台切回前台；从当前页面切到其他页面，再从其他页面切回当前页面，防止动画停止。
        rotationAnim.isRemovedOnCompletion = false
        
        // 给控件添加动画
        rotateView.layer.add(rotationAnim, forKey: nil)
    }
    
}
